
#include "../include/Comm.hpp"


int main()
{
    signal(SIGCHLD, SIG_IGN);
    for (int i = 0; i < 10; i++)
    {
        pid_t pid = fork();
        if (pid < 0)
        {
            LOG(ERROR, "fork error, errno: %d -> %s", errno, strerror(errno));
            return -1;
        }
        else if (pid == 0)
        {
            Socket client;
            client.CreateClient(8888, "127.0.0.1");
            std::string requ = "GET /hello HTTP/1.1\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n";
            while (1)
            {
                assert(client.Send(requ.c_str(), requ.size()) != -1);
                ssize_t n;
                char buffer[1024] = { 0 };
                assert((n = client.Recv(buffer, sizeof buffer - 1)) != -1);
                buffer[n] = 0;
                std::cout << buffer << std::endl;
            }
            client.Close();
            exit(0);
        }
    }

    while (1) sleep(3);

    return 0;
}